<script setup>
import { ref, toRefs, watch } from "vue";
import { storeToRefs } from 'pinia'
import { useMusicStore } from '../store/music'
import SongItem from './SongItem.vue'

const { playList } = storeToRefs(useMusicStore())

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false
  }
})

const { modelValue } = toRefs(props)
const show = ref(false)

watch(() => modelValue.value , () => {
  show.value = modelValue.value
},{deep: true})

const emit = defineEmits(['update:modelValue'])

const handleClose = () => {
  show.value = false
  emit('update:modelValue' , false)
}
</script>

<template>
  <transition>
    <div v-show="show" @click="handleClose" :class="`playlist-drawer animate__animated ${show?'animate__fadeInRight':'animate__fadeOutRight'}`">
      <transition>
        <div @click.stop class="drawer-box">
          <div class="play-list">
            <h3>播放列表</h3>
            <span class="t-f"><span class="iconfont icon-tianjiagedan"></span>收藏全部</span>
            <span class="t-f"><span class="iconfont icon-qingkong"></span>清空</span>
          </div>
          <div class="drawer-box-main">
            <div v-for="item in playList" :key="item.id">
              <song-item :item="item"/>
            </div>
          </div>
        </div>
      </transition>
    </div>
  </transition>
</template>

<style scoped lang="scss">
.play-list {
  width: 100%;
  height: 60px;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  padding: 0 24px;
  border-bottom: 1px solid #dbdbdb;
  h3 {
    flex: 1;
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 1px;
    color: #000000;
    line-height: 0;
    display: flex;
    align-items: center;
  }
  span {
    color: #32363f;
    font-size: 14px;
    letter-spacing: 1px;
    line-height: 0;
    display: flex;
    align-items: center;
    .iconfont {
      margin-right: 6px;
    }
    .icon-tianjiagedan {
      font-size: 12px;
    }
    .icon-qingkong {
      font-size: 18px;
    }
  }
}
.t-f {
  margin-right: 12px;
  &:last-child {
    margin-right: 0;
  }
}
.playlist-drawer {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  z-index: 99999;
  display: flex;
  justify-content: flex-end;
  position: fixed;
  left: 0;
  top: 0;
}
.drawer-box {
  width: 420px;
  height: 100%;
  background: #fff;
  border-radius: 16px 0 0 16px;
  box-shadow: rgba(0, 0, 0, 0.1) 0px 1px 2px 0px;
  display: flex;
  flex-direction: column;
}
.drawer-box-main {
  flex: 1;
  box-sizing: border-box;
  padding: 0 24px;
  overflow: hidden;
  overflow-y: scroll;
  &::-webkit-scrollbar {
    appearance: none;
    width: 0;
  }
}
</style>
